import unittest
import parameterized as parameterized
import logging
from apiAutomation import utils
from apiAutomation.api.adduser import UserApi
from apiAutomation.api.login import LoginApi


class TestUser(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        # 获取登录后的token
        cls.token = LoginApi().get_token()
        # 创建用户操作类
        cls.user_api = UserApi(cls.token)

    # 添加用户
    # @unittest.skip("此用例暂时跳过不执行")
    # @parameterized.parameterized.expand(utils.read_file("login", "add_user", "username,password,role_id,status_code,code,msg"))
    # def test01_add_user(self, username, password, role_id, status_code, code, msg):
    #     # 添加用户
    #     res_add_uesr = self.user_api.add_user(username, password, role_id)
    #     # 断言
    #     utils.common_assert(self, res_add_uesr, status_code, code, msg)
    #     # # 输出日志
    #     logging.info("添加用户的日志结果为：{}".format(res_add_uesr.json()))

    # 查看用户是否存在
    @parameterized.parameterized.expand(utils.read_file("login", "query_user_exit", "username,status_code,code,msg"))
    def test02_query_user_exit(self, username, status_code, status, msg):
        # 查询用户是否存在
        res_query_user_exit = self.user_api.query_user_exit(username)
        # 断言
        utils.common_assert(self, res_query_user_exit, status_code, status, msg)
        # 输出日志
        logging.info("查询用户是否存在的输出日志为:{}".format(res_query_user_exit.json()))

    # 修改账户
    def tesr03_update_user(self):
        pass
